// Learn TypeScript:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const { ccclass, property, requireComponent } = cc._decorator;

@ccclass
@requireComponent(cc.ParticleSystem)
export default class StoneExplosion extends cc.Component {

    private _particle: cc.ParticleSystem = null

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this._particle = this.node.getComponent(cc.ParticleSystem)
    }

    start() {
    }

    update(dt: number) {
        let self = this
        this._particle["_simulator"].particles.forEach(element => {
            if (element.pos.y <= -self.node.y + 64) {
                element.pos.y = -self.node.y + 64 + element.size / 2
                //element.radialAccel = -3000
            }
        });
    }

    onDestroy() {
        cc.log("destroy")
    }
}
